package com.cskaoyan.service;

import com.cskaoyan.bean.MarketCoupon;
import com.cskaoyan.bean.MarketFootprint;
import com.cskaoyan.bean.MarketFootprintExample;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketFootprintMapper;
import com.cskaoyan.util.MyBatisUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class AdminFootprintServiceImpl implements AdminFootprintService {
    @Override
    public CommonData<MarketCoupon> list(Integer userId, Integer goodsId, Integer page, Integer limit, String sort, String order) {

        MarketFootprintExample marketFootprintExample = new MarketFootprintExample();

        MarketFootprintExample.Criteria criteria = marketFootprintExample.createCriteria();

        if (userId!=null){

            criteria.andUserIdEqualTo(userId);

        }

        if (goodsId!=null){

            criteria.andGoodsIdEqualTo(goodsId);



        }

        SqlSessionFactory sqlSessionFactory = MyBatisUtil.getSqlSessionFactory();

        SqlSession sqlSession = sqlSessionFactory.openSession();

        PageHelper.startPage(page, limit);

        MarketFootprintMapper mapper = sqlSession.getMapper(MarketFootprintMapper.class);


        List <MarketFootprint> marketFootprints = mapper.selectByExample(marketFootprintExample);

        if (sqlSession != null) {

            sqlSession.close();

        }

        return   CommonData.data(new PageInfo(marketFootprints));


    }
}
